Skip to content

Flush stdout before slow stop in stop-all (fixes #256)#261

Merged
sdairs merged 1 commit into
mainfrom
issue-256-stop-output-flush
Jun 18, 2026
Merged

Flush stdout before slow stop in stop-all (fixes #256)#261
sdairs merged 1 commit into
mainfrom
issue-256-stop-output-flush

Conversation

@sdairs

@sdairs sdairs commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #256chctl local server stop-all (and the global variant) showed no output for a few seconds, then Stopping 'default'... stopped appeared all at once, making it look like the app had frozen.

The two stop-all handlers in local/mod.rs printed the in-progress Stopping '<name>'... message with print! (no trailing newline) and then ran the graceful kill, which sleeps up to ~2.6s per server (SIGTERM wait + optional SIGKILL wait). With no newline, Rust's line-buffered stdout held the text until the trailing println!(" stopped") ran after the delay — so the whole line landed at once.

This flushes stdout immediately after the print! so the prompt is visible before the kill runs. The final output text is unchanged (Stopping 'X'... stopped on one line); only the timing changes — Stopping 'X'... now appears right away and stopped is appended once the kill completes.

The single-server stop and stop_server_global paths already use println! (which flushes on the newline), so they were left unchanged.

Testing

  • cargo build and cargo clippy clean (no unused-import warning for Write).
  • --json output path is unchanged (still behind the if !json guard).
  • No automated test added: these handlers spawn/kill real processes and sleep, the existing suite has no coverage for them, and flush behaviour isn't observable via unit tests.

🤖 Generated with Claude Code


Note

Low Risk
CLI-only UX timing change with no effect on kill logic, JSON output, or server lifecycle.

Overview
Fixes #256: chctl local server stop-all (project-scoped and --global) looked frozen because the Stopping '…'... line used print! without a newline and only appeared once the trailing stopped ran after ~2.6s graceful kill per server.

Both stop_all_servers_local and stop_all_servers_global now call stdout().flush() immediately after the print!, so the in-progress text shows before kill_server / kill_server_by_pid. Final line text is unchanged; --json paths are untouched. Single-server stop paths already use println! and were not modified.

Reviewed by Cursor Bugbot for commit b6543c0. Bugbot is set up for automated code reviews on this repo. Configure here.

The local/global `stop-all` handlers printed the in-progress
"Stopping '<name>'..." message with `print!` (no newline) and then ran
the graceful kill, which sleeps up to ~2.6s per server. With no newline,
line-buffered stdout held the text until the trailing `println!(" stopped")`
ran after the delay, so the whole line landed at once and looked frozen.

Flush stdout immediately after the `print!` so the prompt is visible
before the kill runs; " stopped" is then appended to the same line.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sdairs sdairs requested a review from iskakaushik as a code owner June 16, 2026 10:00

@iskakaushik iskakaushik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sdairs sdairs merged commit be149d9 into main Jun 18, 2026
3 checks passed
@theory

theory commented Jun 19, 2026

Copy link
Copy Markdown

Actually, I think the issue is that it's waiting to collect the information about what's running, but doesn't emit any output to say so.

@sdairs sdairs deleted the issue-256-stop-output-flush branch June 19, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Delay in stop output

3 participants